<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .contaienr {
            width: 600px;
            height: 400px;
            margin: 0 auto;
        }

        /* .btns{
            width: ;
            margin: 0 auto;
        } */
        .btns {
            text-align: center;
            margin: 20px 0
        }

        .box {
            width: 200px;
            height: 200px;
            margin: 0 auto;
            background-color: rgb(49, 45, 45);
            transition: all 1s;
            color: aliceblue;
        }

        .width {
            width: 420px;
        }

        .height {
            height: 420px;
        }

        .red-color {
            background-color: rgb(240, 95, 95);
        }

        .box-hidden {
            opacity: 0;
        }
    </style>
</head>

<body>
    <div class="contaienr">
        <div class="btns">
            <button class="btn widther">变宽</button>
            <button class="btn heighter">变高</button>
            <button class="btn color">变色</button>
            <button class="btn hidden">隐藏</button>
            <button class="btn reset">重置</button>
        </div>
        <div class="box ">
            box
        </div>
        <p>看看盒子</p>
    </div>
    <script>
        let widthBtn = document.querySelector('.widther')
        let heightBtn = document.querySelector('.heighter')
        let colorBtn = document.querySelector('.color')
        let hiddenBtn = document.querySelector('.hidden')
        let resetBtn = document.querySelector('.reset')
        let boxEle = document.querySelector('.box')

        // widthBtn.onclick = function(){
        //     boxEle.style.width = '300px'
        // }

        widthBtn.onclick = function () {
            boxEle.classList.add('width')
        }

        heightBtn.addEventListener('click', function () {
            boxEle.classList.add('height')
        })

        function changeColor() {
            console.log('12346')
            boxEle.classList.add('red-color')
        }
        colorBtn.addEventListener('click', changeColor)

        function hide() {
            //给元素添加一个class = box-hidden
            boxEle.classList.add('box-hidden')
            //添加一个事件监听，监听过渡效果完成。这个监听只执行一次
            boxEle.addEventListener('transitionend', function () {
                boxEle.style.display = 'none'
            },{once:true})
        }

        hiddenBtn.onclick = hide

        function reset(){
            boxEle.className = 'box'
            boxEle.style.display = 'block'
        }
        resetBtn.onclick = reset




    </script>
</body>

</html>